import { Component, OnInit, ViewChild, ElementRef, AfterViewInit } from '@angular/core';

@Component({
  selector: 'app-parent',
  templateUrl: './parent.component.html',
  styleUrls: ['./parent.component.less']
})
export class ParentComponent implements OnInit, AfterViewInit {


  myName = 'haha';

  nameArr = ['张三', '李四', ' ', '钱多多'];

  // 父组件通过模板变量获取子组件实例
  @ViewChild('child', { static: true })
  child: ElementRef;

  constructor() { }
  ngAfterViewInit(): void {
    console.log(this.child);
  }
  ngOnInit() {
  }

  changeName(name: string) {
    console.log('子组件通知父组件更新值啦', name);
  }

}
